﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb.admin
{
    public partial class companyList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("FC", 1))
                {
                    drpBind();
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        void drpBind()
        {
            DataTable dt = logic.sysCode.companyTypeList();
            ddl_Type.DataSource = dt;
            ddl_Type.DataBind();
            ddl_Type.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--请选择--", ""));
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("isCheck=1");
            if (txt_companyName.Text.Trim() != "")
                where.AppendFormat("and company like '%{0}%'", txt_companyName.Text.Trim());
            if (ddl_Type.SelectedValue != "")
                where.AppendFormat("and type = '{0}'", ddl_Type.SelectedValue.Trim());
            if (txt_mobile.Text.Trim() != "")
                where.AppendFormat("and mobile = '{0}'", txt_mobile.Text.Trim());
            DataSet ds = logic.company.select(where.ToString(), "isDel asc,companyId desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
       
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            rptBind();
        }

        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                if (e.CommandArgument.ToString() == "IsDel")
                {
                    int cid = 0;
                    int.TryParse(e.CommandName.ToString(),out cid);
                    try
                    {
                        logic.company.P_CompanyIsdel(cid);
                        rptBind();
                    }
                    catch(Exception ee) { Library.Script.ClientMsg(ee.Message); }
                    
                }
            }
        }
    }
}
